//**************************************************//
// Unique Keychain Arduino Code                     //
// ECE 387, Miami University, Spring 2013           // 
// Created By: Andrew Heldt, Lee Mondini, and       //
// Shiloh Womack                                    //
//**************************************************//
#include <Stepper.h> 

const int inPin = A0; // Input connected to analog pin A0
int pressed = 0; // Has the button been pressed
int locked = 0;
Stepper motor(100,8,9,10,11);

void setup()
{
   motor.setSpeed(10);
   Serial.begin(9600);
}

void loop()
{
  pressed = analogRead(inPin);   
   
  delay(2000);  
  
  // Had these for testing purposes
  //Serial.println(pressed);
  //Serial.println(locked);
   
  if(pressed > 0 && locked == 1)
  {
    // Unlock the door, aka turn right
      locked = 0;
      motor.step(100);
      delay(500);    
  }
  else if(pressed == 0 && locked == 0)
    {  
      // Lock the door, aka turn left
        locked = 1;
        motor.step(-100);
        delay(500);
    }
}
